package com.atguigu.tingshu.account.mapper;

import com.atguigu.tingshu.model.account.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface UserAccountMapper extends BaseMapper<UserAccount> {
    @Update("update user_account set available_amount = available_amount- #{amount},total_amount = total_amount- #{amount},total_pay_amount=total_pay_amount+ #{amount}\n" +
            "where  available_amount >= #{amount} and user_id = #{userId} and is_deleted=0")
    Long checkAndDeduct(@Param("amount") BigDecimal amount, @Param("userId") Long userId);
}
